<template>
  <div>
    <div class="wrapper">
      <TopFilter :list="topFilterList" :cols="2" labelWidth="80" @filterChange="changeHandler" @onCollapse="collapseHandle"></TopFilter>
      <!-- :fetchapi="fetchApi" -->
      <FilterTable
        ref="table"
        :columns="columns"
        :params="fetchParams"
        :datakey="'rows'"
        :onColumnsChange="columns => (this.columns = columns)"
        :onRowSelectChange="selectRow"
        selectionType="single"
        :onEnterEvent="enterHandle"
      >
      </FilterTable>
    </div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDialog">关闭</el-button>
      <el-button type="primary" @click="selectDialog">确定</el-button>
    </div>
  </div>
</template>

<script>
// import { customerSearch } from '@/api/finIns/insurance/new_clues';
// import { getUserInfoByRolePosition } from '@/api/finIns/financial/loans_clues';
import { getUserInfo } from '@/api/customerCare/saleVisit/careTaskSearch';
import { notifyAction } from '@/utils';

export default {
  name: '',
  props: {
    telPhone: {
      type: String
    }
  },
  data() {
    this.BaseTable = null;
    this.salesList = [];
    return {
      topFilterList: this.createtopFilterList(),
      fetchParams: { sign: '1' },
      rowData: [],
      // fetchApi: customerSearch,
      columns: this.createTableColumns()
    };
  },
  mounted() {
    getUserInfo().then(res => {
      if (res.resultCode == 200) {
        let param = {
          positionCode: '10061010',
          companyId: res.data.userInfo.companyId,
          ownerCode: res.data.userInfo.ownerCode // 销售顾问code
        };
        // getUserInfoByRolePosition(param).then(res => {
        //   if (res.resultCode == 200) {
        //     this.salesList = res.data.map(x => ({ value: x.userId, text: x.employeeName }));
        //   } else {
        //     this.$message.error('获取销售顾问列表失败!');
        //   }
        // });
      } else {
        this.$message.error('获取当前登录用户信息失败!');
      }
    });
  },
  methods: {
    selectDialog() {
      if (!this.rowData.length) {
        return notifyAction('请选择一条数据', 'warning');
      }
      if (this.rowData[0].salesConsultant !== null) {
        if (this.salesList.find(item => item.value === Number(this.rowData[0].salesConsultant)) !== undefined) {
          var salesName = this.salesList.find(item => item.value === Number(this.rowData[0].salesConsultant)).text;
          this.rowData[0].salesConsultant = salesName;
        }
      }
      this.closeDialog(this.rowData);
    },
    closeDialog(val) {
      this.$emit('close', false, val);
    },
    changeHandler(val) {
      this.fetchParams = { ...val, sign: '1' };
    },
    enterHandle() {
      this.selectDialog();
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    createTableColumns() {
      return [
        {
          title: '客户名称',
          dataIndex: 'customerName',
          showOverflowTooltip: true,
          width: 90
        },
        {
          title: '电话',
          dataIndex: 'phone',
          showOverflowTooltip: true,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '底盘号',
          dataIndex: 'vin',
          showOverflowTooltip: true,
          sorter: true,
          filter: true,
          filterType: 'input',
          minWidth: 150
        },
        {
          title: '牌照号',
          dataIndex: 'carPlate',
          showOverflowTooltip: true,
          width: 90
        },
        {
          title: '证件号码',
          dataIndex: 'certificateNo',
          showOverflowTooltip: true
        }
      ];
    },
    selectRow(val) {
      this.rowData = val;
    },
    createtopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '关键字查询:',
          fieldName: 'keywordSearch',
          initialValue: this.telPhone
        }
      ];
    }
  }
};
</script>

<style lang="less" scoped></style>
